home *** CD-ROM | disk | FTP | other *** search
- /*pascal format string functions Written by and property of: Eric J. Hayes*/
- /*non-profit use of this library must be accompanyed by a credit to myself.*/
- /*sale of all or any part of this library or it's headers prohibited without*/
- /*written permission of myself*/
- /* ®1987-1991 Eric J. Hayes*/
-
- #pragma mark HEADERS
- #include "pStr.h"
-
-
- #pragma mark PROTOS
- void pStrCpy(char*,char*);
- void pStrCat(char*,char*);
- void pRightJust(char*,short);
- short pStrCmp(char*,char*,short,short,short);
-
-
- void pStrCpy(outStr,inStr)
- char* inStr;
- char* outStr;
- {
- short xx;
- short in = inStr[0] & 0x00FF;
- short out = outStr[0] & 0x00FF;
-
- for (xx=0; xx<=in; xx++)
- outStr[xx] = inStr[xx];
- }
-
- void pStrCat(outStr,inStr)
- char* inStr;
- char* outStr;
- {
- short xx;
- short in = inStr[0] & 0x00FF;
- short out = outStr[0] & 0x00FF;
-
- if ( (in + out) > 255 ) /*make sure there is enough room*/
- {
- in = 255 - out;
- }
-
- for (xx=1; xx<=in; xx++)
- outStr[out+xx] = inStr[xx];
-
- outStr[0] = out+in;
- }
-
- void pRightJust(theStr,places)
- char* theStr;
- short places;
- {
- Str255 tempStr;
- short theOffset;
- short xx;
-
- if ( theStr[0] < places )
- {
- pStrCpy((char*)tempStr,(char*)theStr);
- theOffset = places - theStr[0];
- theStr[0] = places;
- for(xx=1 ;xx<=places ;theStr[xx++] = ' ');
- for(xx=1 ;xx<=theStr[0] ;theStr[xx+theOffset] = tempStr[xx++]);
- }
- }
-
- short pStrCmp(ned,hay,mode,hayoffset,casetype)
- char* ned;
- char* hay;
- short mode;
- short hayoffset;
- short casetype;
- {
- char tempchar;
- short xx,yy,err,loops;
- Str255 temp_ned,temp_hay;
-
- pStrCpy((char*)temp_ned,ned);
- pStrCpy((char*)temp_hay,hay);
-
- if ( casetype == 1 )
- {
- UprString (temp_ned,FALSE);
- UprString (temp_hay,FALSE);
- }
-
- switch(mode)
- {
- case str_equals:
- if ( hayoffset == 0 )
- xx = 0;
- else
- xx = 1;
- for (;xx<=temp_ned[0];xx++)
- if ( temp_ned[xx] != temp_hay[xx+hayoffset] )
- return(BAD);
- break;
- case str_contains:
- if (temp_ned[0] == temp_hay[0])
- {
- err = pStrCmp(ned,hay,str_equals,0,casetype);
- return(err);
- }
- else
- {
- loops = temp_hay[0] - temp_ned[0];
- for(xx=0;xx<=loops;xx++)
- {
- err = pStrCmp(ned,hay,str_equals,xx,casetype);
- if ( err == GOOD )
- return(GOOD);
- }
- return(BAD);
- }
- break;
- case str_starts:
- for (xx=1;xx<=temp_ned[0];xx++)
- if ( temp_ned[xx] != temp_hay[xx] )
- return(BAD);
- break;
- case str_ends:
- yy = temp_hay[0] - temp_ned[0];
- for (xx=1;xx<=temp_ned[0];xx++)
- if ( temp_ned[xx] != temp_hay[xx+yy] )
- return(BAD);
- break;
- }
-
- return(GOOD);
- }
-
-